import {Component, OnInit, Renderer2, ViewChild, ViewContainerRef, ViewEncapsulation} from '@angular/core';
import {animate, state, style, transition, trigger} from "@angular/animations";
import {GlobalEvent} from '../support/event.definition';
import {AppService} from "../app.service";
import {LoadComponent} from "../support/annotation";

@Component({
  selector: '.ss-platform-main-wraper',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.scss'],
  animations: [
    trigger("toggle", [
      state('false', style({transform: 'translate3d(0px,0,0)'})),
      state('true', style({transform: 'translate3d(-320px,0,0)'})),
      transition("false <=> true", animate(200))
    ])
  ],
  host: {"[@toggle]": "isLeftSlideMainWraper"},
  encapsulation: ViewEncapsulation.None
})
@LoadComponent(GlobalEvent.ShowMain)
export class MainComponent implements OnInit {

  GlobalEvent: typeof GlobalEvent = GlobalEvent;
  // 是否左滑主体
  isLeftSlideMainWraper: boolean = false;

  @ViewChild("container", {read: ViewContainerRef, static: true})
  container: ViewContainerRef;

  constructor(public $app: AppService, private renderer: Renderer2) {
    // 右侧面板
    // $app.subscribe([GlobalEvent.LoadSidebarNotice, GlobalEvent.LoadSidebarProcedure, GlobalEvent.HideSidebar], () => this.isLeftSlideMainWraper = true);
    $app.subscribe(GlobalEvent.HideSidebar, () => this.isLeftSlideMainWraper = false);
  }

  ngOnInit(): void {
    // 数据初始化完成
    setTimeout(() => this.$app.publish(GlobalEvent.HideLoading), 200);

  }

}
